package com.vencent.spring.controller;

import javax.servlet.http.Part;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class HomeController {
	
	@RequestMapping("/my/home")
	public String myHome(){
		return "home";
	}
	
	@ResponseBody
	@RequestMapping(value = "/my/fileUpload1", method=RequestMethod.POST)
	public String up1(MultipartFile imgUp){
		return imgUp.getOriginalFilename();
	}
	
	/**
	 * 采用这种方式就不必配置MultipartResolver, 但是任然要配置javax.servlet.MultipartConfigElement ,
	 * 可以在xml通过<multipart-config>中配置
	 * 或者在java中配置通过Dynamic配置
	 * @param imgUp
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/my/fileUpload2", method=RequestMethod.POST)
	public String up2(@RequestPart Part imgUp){
		return imgUp.getSubmittedFileName();
	}
	
}
